<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!-- 搜索 -->
      <div class="filter-item">訂單銷售時間:</div><date-range-picker
        v-model="modelEndDate"
        clearable
        placeholder="时间"
        class="filter-item"
        :fix-date.sync="timeSlot"
        @keyup.enter.native="crud.toQuery"
        @change="getTimeSlot"
      />
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation>
        <template #right>
          <rrOperation :crud="crud" />
          <el-button
            class="filter-item"
            type="warning"
            :disabled="modelEndDate.length < 1"
            @click="exportOrderSale"
          >導出
          </el-button>
        </template>
      </crudOperation>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        row-key="id"
        :data="crud.data"
        stripe
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column prop="member" label="会员" width="150px" />
        <el-table-column prop="orderSn" label="订单编号" width="110px" />
        <el-table-column prop="address" label="收货地址" width="200px" />
        <el-table-column prop="payMethod" label="	支付方式" />
        <el-table-column prop="totalPay" label="总支付" align="right"/>
        <el-table-column prop="orderDate" label="订单日期" width="140px" />
        <el-table-column prop="deliveryDate" label="	收货日期" width="150px" />
        <el-table-column prop="cash" label="現金" width="50px" align="right"/>
        <el-table-column prop="alipay" label="Alipay" width="60px" align="right"/>
        <el-table-column prop="cloudQuickPass" label="云闪付" width="60px" align="right"/>
        <el-table-column prop="consumerCard" label="消費卡" width="60px" align="right"/>
        <el-table-column prop="giftCartAmount" label="礼金券" width="60px" align="right"/>
        <el-table-column prop="icbc" label="icbc" align="right"/>
        <el-table-column prop="mpay" label="mpay" width="60px" align="right"/>
        <el-table-column prop="unionPay" label="Visa/Master/UnionPay" align="right"/>
        <el-table-column prop="wallet" label="钱包" align="right"/>
        <el-table-column prop="wx" label="微信" align="right"/>
        <el-table-column prop="returnAmount" label="退款金額" align="right"/>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudReport from '@/api/fms/report'
import CRUD, { presenter, header, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import { mapGetters } from 'vuex'
import { downloadFile } from '@/utils'
import dateRangePicker from '@/components/DateRangePicker'

export default {
  name: 'OrderSale',
  components: { pagination, crudOperation, rrOperation, dateRangePicker },
  mixins: [presenter(), header(), crud()],
  dicts: ['true_false'],
  cruds() {
    return CRUD({ title: '訂單銷售統計表', url: 'report/orderSale', sort: [], crudMethod: { ...crudReport }, optShow: {}})
  },
  data() {
    return {
      modelEndDate: [],
      timeSlot: ''
    }
  },
  computed: {
    ...mapGetters(['imagesUploadApi', 'baseApi'])
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    exportOrderSale() {
      crudReport.exportOrderSale({ startTime: this.query.startTime, endTime: this.query.endTime }).then(res => {
        if (res.code !== undefined && res.code !== 0) {
          this.$notify({
            title: '失敗',
            message: res.message,
            type: 'error'
          })
          return
        }
        downloadFile(res, this.crud.title + '数据', 'xlsx')
      })
    },
    getTimeSlot(sel) {
      this.query.startTime = sel[0]
      this.query.endTime = sel[1]
      this.crud.toQuery()
    }
  }
}
</script>

<style scoped>

</style>
